import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Form, Input, Upload, Button, Radio } from 'antd'
import { UploadOutlined } from '@ant-design/icons'
import _ from 'loadsh'
import { Line, Cell } from '@components/ApprovePre/Approve'
import { getUploadProps } from '@js/tool'

const { Item } = Form
const { TextArea } = Input
export default class StepThreeInput extends Component {
  state = {
    keyTitleMap: {},
    fileList: []
  }

  initKeyTitleMap () {
    const map = {}
    const list = _.get(this.props.instance || {}, 'currentStep.vars', [])
    list.forEach(li => {
      map[li.key] = li.title
    })
    this.setState({
      keyTitleMap: map
    })
  }

  componentDidUpdate (prev) {
    if (this.props.instance !== prev.instance) {
      this.initKeyTitleMap()
    }
  }

  componentDidMount () {
    this.initKeyTitleMap()
  }

  render () {
    const { keyTitleMap } = this.state
    return (
      <div>
        <Line>
          <Cell>
            <Item labelCol={{ flex: '128px' }} label='操作者'>
              <span>{this.props.userInfo.realname}</span>
            </Item>
          </Cell>
        </Line>
        <Line>
          <Cell style={{ width: '65%' }}>
            <Item labelCol={{ flex: '128px' }} name={['vars', 'closure_bizleader_remark']} label={keyTitleMap.closure_bizleader_remark} rules={[{ required: true, message: `${keyTitleMap.closure_bizleader_remark}不能为空` }]}>
              <TextArea rows={3} placeholder={`请输入${keyTitleMap.closure_bizleader_remark}`} />
            </Item>
          </Cell>
        </Line>
        <Line>
          <Cell style={{ width: '65%' }}>
            <Item labelCol={{ flex: '128px' }} name={['vars', 'closure_isonlineaudit']} label={keyTitleMap.closure_isonlineaudit} rules={[{ required: true, message: `${keyTitleMap.closure_isonlineaudit}不能为空` }]}>
              <Radio.Group>
                <Radio value='是'>是</Radio>
                <Radio value='否'>否</Radio>
              </Radio.Group>
            </Item>
          </Cell>
        </Line>
        <Line>
          <Cell>
            <Item name='file' labelCol={{ flex: '108px' }} label={keyTitleMap.closure_document_fixed}>
              <Upload {...getUploadProps.call(this, this.props.formRef)}>
                <Button>
                  <UploadOutlined /> 上传文件
                </Button>
              </Upload>
            </Item>
          </Cell>
        </Line>
      </div>
    )
  }
}

StepThreeInput.proptypes = {
  caseDetail: PropTypes.object,
  userInfo: PropTypes.object,
  instance: PropTypes.object,
  formRef: PropTypes.object,
  dictionaries: PropTypes.object
}

StepThreeInput.defaultProps = {
  caseDetail: {},
  userInfo: {},
  instance: {},
  formRef: {},
  dictionaries: {}
}
